{extend name="member/common/login_layout" /}

{block name="content"}

<!-- PublicHeadLayout End -->
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>

<div class="nc-login-layout">
	<div class="left-pic"><img src="{$lpic}"  border="0"></div>
	<div class="nc-login">
		<div class="arrow"></div>
		<div class="nc-login-mode">
			<ul class="tabs-nav">
				<li><a href="#default">用户登录<i></i></a></li>
				<?php if (sysconf('sms_login') == 1){?>
				<li><a href="#mobile">手机验证码登录<i></i></a></li>
				<?php } ?>
			</ul>
			<div id="tabs_container" class="tabs-container">
				<div id="default" class="tabs-content">
					<form id="login_form" class="nc-login-form layui-form" method="post">

						<input type="hidden" name="__token__" value="{$Request.token}" />
						<!--<input type="hidden" name="form_submit" value="ok" />-->
						<!--<input name="nchash" type="hidden" value="<?php echo getNchash();?>" />-->
						<dl>
							<dt>账&nbsp;&nbsp;&nbsp;号：</dt>
							<dd>
								<input type="text" class="text" autocomplete="off"  name="username" lay-verify="username" tipMsg="可使用已注册的用户名或手机号登录" id="user_name"  >
							</dd>
						</dl>
						<dl>
							<dt>密&nbsp;&nbsp;&nbsp;码：</dt>
							<dd>
								<input type="password" class="text" name="password" autocomplete="off" lay-verify="password" tipMsg="6-20个大小写英文字母、符号或数字" id="password">
							</dd>
						</dl>
						<?php if(sysconf('captcha_status_login') == '1') { ?>
						<div class="code-div mt15">
							<dl>
								<dt>验证码：</dt>
								<dd>
									<input type="text" name="captcha" autocomplete="off" class="text w100" lay-verify="captcha" tipMsg="输入验证码" id="captcha" size="10" />
								</dd>
							</dl>
							<span><img src="{:url('verify_code')}" name="codeimage" id="codeimage"> <a class="makecode" href="javascript:void(0)" onclick="javascript:document.getElementById('codeimage').src='{:url(\'verify_code\')}?t=' + Math.random();">看不清，换一张</a></span></div>
						<?php } ?>
						<div class="handle-div">
							<span class="auto"><input lay-ignore="" type="checkbox" class="checkbox" name="auto_login" value="1">七天自动登录<em style="display: none;">请勿在公用电脑上使用</em></span>
							<a class="forget" href="{:url('member/Login/forget_password')}">忘记密码？</a>
						</div>
						<div class="submit-div">
							<input type="submit" class="submit" lay-submit="" lay-filter="ajax_default_login" value="登&nbsp;&nbsp;&nbsp;录">
							<input type="hidden" value="{$Think.get.ref_url}" name="ref_url">
						</div>
					</form>
				</div>
				<?php if (sysconf('sms_login') == 1){?>
				<div id="mobile" class="tabs-content">
					<form id="post_form" method="post" class="nc-login-form layui-form" action="">

						<!--<input type="hidden" name="form_submit" value="ok" />-->
						<!--<input name="nchash" type="hidden" value="<?php echo getNchash();?>" />-->
						<dl>
							<dt>手机号：</dt>
							<dd>
								<input name="phone" type="text" class="text" id="phone" lay-verify="phone" tipMsg="可填写已注册的手机号接收短信" autocomplete="off" value="" >
							</dd>
						</dl>
						<div class="code-div">
							<dl>
								<dt>验证码：</dt>
								<dd>
									<input type="text" name="captcha" class="text w100" lay-verify="captcha" tipMsg="输入验证码" id="image_captcha" size="10" />

								</dd>
							</dl>
							<span><img src="{:url('verify_code')}" title="看不清，换一张" name="codeimage" id="sms_codeimage"> <a class="makecode" href="javascript:void(0);" onclick="javascript:document.getElementById('sms_codeimage').src='{:url('verify_code')}?rand=' + Math.random()">看不清，换一张</a></span> </div>

						<div class="tiptext" id="sms_text">正确输入上方验证码后，点击<span> <a href="javascript:void(0);" onclick="get_sms_captcha('2')"><i class="icon-mobile-phone"></i>发送手机验证码</a></span>，查收短信将系统发送的“6位短信验证码”输入到下方验证后登录。</div>
						<dl>
							<dt>短信验证：</dt>
							<dd>
								<input type="text" name="sms_captcha" autocomplete="off" class="text" lay-verify="sms_captcha" tipMsg="输入6位短信验证码" id="sms_captcha" size="15" />

							</dd>
						</dl>
						<div class="submit-div">
							<input type="submit" id="submit" class="submit" lay-submit="" lay-filter="ajax_mobile_login" value="登&nbsp;&nbsp;&nbsp;录">
							<input type="hidden" value="<?php echo $_GET['ref_url']?>" name="ref_url">
						</div>
					</form>
				</div>
				<?php } ?>
			</div>
		</div>
		<div class="nc-login-api" id="demo-form-site">
			{if (sysconf('qq_isuse') == 1 || sysconf('sina_isuse') == 1 || sysconf('weixin_isuse') == 1)}
			<h4>使用合作网站账号登录：</h4>
			{if (sysconf('qq_isuse') == 1)}
			<a href="{:url('member/Connectqq/index')}" title="QQ账号登录" class="qq"><i></i>QQ</a>
			{/if}
			{if (sysconf('sina_isuse') == 1)}
			<a href="{:url('member/Connectsina/index')}" title="新浪微博账号登录" class="sina"><i></i>新浪微博</a>
			{/if}
			{if (sysconf('weixin_isuse') == 1)}
			<a href="javascript:void(0);" onclick="ajax_form('weixin_form', '微信账号登录', '{:url(\'member/Connectwx/index\')}', 360);" title="微信账号登录" class="wx"><i></i>微信</a>
			{/if}
			{/if}
		</div>
	</div>
	<div class="clear"></div>
</div>
<script>
    $(function () {
        //初始化Input的灰色提示信息
        $('input[tipMsg]').inputTipText({pwd: 'password'});
        //登录方式切换
        $('.nc-login-mode').tabulous({
            effect: 'flip'//动画反转效果
        });
        var div_form = '#default';
        $(".nc-login-mode .tabs-nav li a").click(function () {
            if ($(this).attr("href") !== div_form) {
                div_form = $(this).attr('href');
                $("" + div_form).find(".makecode").trigger("click");
            }
        });

        // 勾选自动登录显示隐藏文字
        $('input[name="auto_login"]').click(function () {
            if ($(this).attr('checked')) {
                $(this).attr('checked', true).next().show();
            } else {
                $(this).attr('checked', false).next().hide();
            }
        });
    });
</script>
<?php if (sysconf('sms_login') == 1){?>
<!--<script type="text/javascript" src="__MEMBER_PATH__/js/connect_sms.js" charset="utf-8"></script>-->
<script>
    $(function(){
//        $("#post_form").validate({
//            errorPlacement: function(error, element){
//                var error_td = element.parent('dd');
//                error_td.append(error);
//                element.parents('dl:first').addClass('error');
//            },
//            success: function(label) {
//                label.parents('dl:first').removeClass('error').find('label').remove();
//            },
//            submitHandler:function(form){
//                ajaxpost('post_form', '', '', 'onerror');
//            },
//            onkeyup: false,
//            rules: {
//                phone: {
//                    required : true,
//                    mobile : true
//                },
//                captcha : {
//                    required : true,
//                    minlength: 4,
//                    remote   : {
//                        url : 'checkVerifyCode',
//                        type: 'get',
//                        data:{
//                            captcha : function(){
//                                return $('#image_captcha').val();
//                            }
//                        },
//                        complete: function(data) {
//                            if(data.responseText == 'false') {
//                                document.getElementById('sms_codeimage').src="{:url('verify_code')}";
//                            }
//                        }
//                    }
//                },
//                sms_captcha: {
//                    required : function(element) {
//                        return $("#image_captcha").val().length == 4;
//                    },
//                    minlength: 6
//                }
//            },
//            messages: {
//                phone: {
//                    required : '<i class="icon-exclamation-sign"></i>请输入正确的手机号',
//                    mobile : '<i class="icon-exclamation-sign"></i>请输入正确的手机号'
//                },
//                captcha : {
//                    required : '<i class="icon-remove-circle" title="请输入正确的验证码"></i>',
//                    minlength: '<i class="icon-remove-circle" title="请输入正确的验证码"></i>',
//                    remote	 : '<i class="icon-remove-circle" title="请输入正确的验证码"></i>'
//                },
//                sms_captcha: {
//                    required : '<i class="icon-exclamation-sign"></i>请输入六位短信验证码',
//                    minlength: '<i class="icon-exclamation-sign"></i>请输入六位短信验证码'
//                }
//            }
//        });
    });
</script>
<?php } ?>

<!-- layer 3.0 -->
<script src="__PUBLIC__/static/plugs/layer/layer.js"></script>

<!-- layui 2.0-->
<link rel="stylesheet" href="__PUBLIC__/static/plugs/layui/css/layui.css">
<script src="__PUBLIC__/static/plugs/layui/layui.js"></script>

<!-- popup js -->
<script language="javascript" src="__PUBLIC__/static/admin/js/popup.js" type="text/javascript"></script>

<script>
    function get_sms_captcha(){
        if($("#phone").val().length == 11){

            $.ajax({
                type: "GET",
                url: '{:url("member/Login/sendSms")}?type=login&mobile=' + $('#phone').val(),
                async: false,
                success: function(res){
//                    popup_jump(res, 1);
                    if(res.state == 200) {

                        $("#sms_text").html(res.message);
                    } else {
//                        showError(res.message);
                        layer.alert(res.message, {
                            icon: 2
                            ,skin: 'layer-ext-moon'
                            ,time: 2000
                        })

                    }
                }
            });
        }
    }
</script>

<script>
//	$(document).ready(function() {
//		function change_seccode() {
//			$('#sms_codeimage').attr('src', '{:url("verify_code")}?rand=' + Math.random());
//		}
//	}
    layui.use(['form'], function() {
        var form = layui.form;

        //自定义验证规则
        form.verify({
            username: function(value){
                if(value == '可使用已注册的用户名或手机号登录' || value.length < 1){
                    return '登录账号不能为空';
                }
            },
            password: function(value){
                if(value == '6-20个大小写英文字母、符号或数字' || value.length < 1){
                    return '密码不能为空';
                }
            },
            captcha: function(value){
                if(value == '输入验证码'){
                    return '验证码不能为空';
                }
                if(value.length < 4){
                    return '验证码至少为4位';
                }
            },
			phone: function (value) {
                if(value == '可填写已注册的手机号接收短信' || value.length < 11){
                    return '请输入正确的手机号';
                }
            },
            sms_captcha: function (value) {
                if(value == '输入6位短信验证码' || value.length < 6){
                    return '请输入六位短信验证码';
                }
            }
        });

        // ajax 提交
        form.on('submit(ajax_default_login)', function(data){
            data.field.login_type = 'username';
            $.post('{:url("member/Login/index")}',data.field,function(res){

                // 返回错误信息 刷新验证码
				if (res.code == 0) {
                    document.getElementById('codeimage').src="{:url('verify_code')}?rand="  + Math.random();
				}
                popup_jump(res, 1); // alert信息
            });
            return false;
        });

        form.on('submit(ajax_mobile_login)', function(data){
            data.field.login_type = 'mobile';
            $.post('{:url("member/Login/index")}',data.field,function(res){

                if (res.code == 0) {
                    document.getElementById('sms_codeimage').src="{:url('verify_code')}?rand="  + Math.random();
				}
                popup_jump(res, 1); // alert信息
            });
            return false;
        });
    });
</script>

{/block}
